﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.JShop.UI;
using System.Data;
using CNVP.Framework;
using CNVP.Framework.Utils;


namespace CNVP.JShop.Web.Admin
{
    public partial class PostAddressList : AdminPage
    {
        BLL.CNVP_PostAddress bll = new BLL.CNVP_PostAddress();
        public int rplistCount = 0;
        public int PageIndex = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 96)) return;//判断页面权限
            if (!string.IsNullOrEmpty(Request.QueryString["Page"]) && Public.IsNumber(Request.QueryString["Page"]))
            {
                PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            }
            if (!IsPostBack)
            {
                StartLoad(PageIndex);
                btDelete.Attributes.Add("onclick", "if(ifCheck()){return confirm('确定删除该记录吗?');}else{alert('请选择记录！');return false;};");
            }
        }

        /// <summary>
        /// PageNavigator1_PageChange 的摘要说明
        /// 分页加载列表函数
        /// </summary>
        protected void StartLoad(int PageIndex)
        {
            int i, j;
            DataTable dt = null;
            int pageNum = 20;
            dt = bll.GetPage(this.GetType().Name, PageIndex, pageNum, out i, out j, null);
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    rplistCount = dt.Rows.Count;//行数
                    //----------------------------------------添加列------------------------------------------------
                    dt.Columns.Add("oProvinceCityArea", typeof(string));
                    dt.Columns.Add("oPostAddress", typeof(string));
                    //----------------------------------------添加列结束--------------------------------------------

                    for (int k = 0; dt.Rows.Count > k; k++)
                    {
                        string PostAddress_Str=new BLL.CNVP_Province().GetSingle_CNVP_ProvinceByCode(dt.Rows[k]["Province"].ToString()).Name + new BLL.CNVP_City().GetSingle_CNVP_CityByCode(dt.Rows[k]["City"].ToString()).Name + new BLL.CNVP_Area().GetSingle_CNVP_AreaByCode(dt.Rows[k]["Area"].ToString()).Name;
                        dt.Rows[k]["oProvinceCityArea"] = PostAddress_Str;
                        dt.Rows[k]["oPostAddress"] =BasePage.CutString(dt.Rows[k]["PostAddress"].ToString(),30);
                    }
                }
            }
            rpList.DataSource = dt;
            rpList.DataBind();
            paging.InnerHtml = Paginator.Pagination(PageIndex, i, j);
        }


        protected void btDelete_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.rpList.Items.Count; i++)
            {
                CheckBox cbCheck = (CheckBox)this.rpList.Items[i].FindControl("cbCheck");
                if (cbCheck.Checked == true)
                {
                    int code = int.Parse(cbCheck.ToolTip);
                    bll.Delete_CNVP_PostAddress(code);
                }
            }
            StartLoad(PageIndex);
        }
    }
}
